<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>天天爆品</title>

<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/third/bootstrap3/bootstrap.min.js" type="text/javascript"></script>
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script>
 
var exceldialog=null;
function uploaddialog(){
	//var param ={id:newproid};
	exceldialog = art.dialog.uploadFile("上传图片",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
}

function uploadcallback(response){
	//alert(response.url);
	//alert(params.id);
	exceldialog.close();
	$("#baoimg").attr("src",response.url);
	$("#onlyimage").val(response.url)
	
}

function edit(hotproid,image,url,seq){
	//alert("ff");
	$("#updateprodiv").find("[name='hotproid']").val(hotproid);
	$("#updateprodiv").find("#baoimg").attr("src",image);
	$("#updateprodiv").find("#onlyimage").val(image);
	$("#updateprodiv").find("[name='url']").val(url);
	$("#updateprodiv").find("[name='seq']").val(seq);
	 dialog = art.dialog({
	        title: "编辑爆品",
	        lock:true,
	        content: document.getElementById('updateprodiv')
	    });
}

function enable(id,enable){
	$.ajax({
		   type: "post",
		   dataType:"json",
		   url: "changeEnable.do",
		   data:{id:id,enable:enable},
		   beforeSend:function(){
			    art.dialog.tips("修改中...");
		   },
		   success: function(data){//成功的时候调用
			   if(data==1){
				   location.reload();
			   }else{
				   alert("修改失败");
			   }
		   }
	});
}
function del(id){
	 if(confirm("是否确认删除？")){
		 $.ajax({
			   type: "post",
			   dataType:"json",
			   url: "delhotproduct.do",
			   data:{id:id},
			   success: function(data){//成功的时候调用
				   if(data==1){
					   alert("删除成功");
					   location.reload();
				   }else{
					   alert("删除失败")
				   }
			   }
		});
	 }
}

function fillinid(productid,productname){
	$("#addprodiv").find("#onlyproductname").val(productname);
	$("#addprodiv").find("#onlyproductid").val(parseInt(productid));
	$("#addprodiv").find("#onlyproducturl").val("/product/"+productid+".html");
	//$("#onlyproductname").val(productname);
	//$("#onlyproductid").val(parseInt(productid));
	alert("选择成功");
	dialogNewub.close();
}


function sub(){
	$(this).attr("disabled","disabled");
	if($("#signupForm").valid()){
	$.ajax({
		   type: "POST",
		   dataType:"json",
		   url: "/admin/admin_add.do",
		   data:$("form").serialize(), //序列表表格内容为字符串
		   beforeSend:function(){
			   art.dialog.tips("加载中.....");
		   },
		   success: function(data){//成功的时候调用
			   if(data.success){
				   location.reload();
			   }
		   }
	});
	
};
}
$().ready(function(){
    $("#signupForm").validate({
    	rules:{
    		name:{
    			required:true,
    			maxlength:10
    		}
    	}
    });
    $("#addhotpros").click(function(){
    	$("#baoimg").attr("src","");
    	$("#onlyimage").val("");
    	$("#addprodiv").find("#onlyproductname").val("");
		$("#addprodiv").find("#onlyproductid").val("");
		$("#addprodiv").find("#onlyproducturl").val("");
		$("#addprodiv").find("#onlyseq").val("");
    	 dialog = art.dialog({
    	        title: "新增爆品",
    	        lock:true,
    	        content: document.getElementById('addprodiv')
    	    });
    });
    function newprosub(index){
    	var ispubOrpro= parseInt($("[name='isproOrpub']:checked").val());
    	$.ajax({
	 		   type: "POST",
	 		   dataType:"json",
	 		   url: "getnewpro.do",
	 		   data:$("#gethotproform").serialize(),  
	 		   success: function(data){ 
	 			   //alert(data.length);
	 			   if(data.length>0){
	 				 $("#theone").nextAll().remove();
	 				 //alert($("#theone").nextAll().length);
	 				 for (var i = 0; i < data.length; i++) {
	 					 if(ispubOrpro==0){
	 						$("#pubtable tr:last").after("<tr>"
				  						+"<td>"+data[i].id+"</td>"
				  						+"<td>"+data[i].productname+"</td>"
					  						+"<td>"
					  							+"<input type='button' value='选择商品' id='choosetohot' onclick='fillinid("+data[i].productid+","+'"'+data[i].productname+'"'+")' class='btn btn-danger btn-xs'/>"
					  						+"</td>"
				  					  +"</tr>"); 
	 					 }else{
	 						$("#pubtable tr:last").after("<tr>"
			  						+"<td>"+data[i].id+"</td>"
			  						+"<td>"+data[i].name+"</td>"
				  						+"<td>"
				  							+"<input type='button' value='选择商品' id='choosetohot' onclick='fillinid("+data[i].id+","+'"'+data[i].name+'"'+")' class='btn btn-danger btn-xs'/>"
				  						+"</td>"
			  					  +"</tr>"); 
	 					 }
					  }
	 				   
	 			   }else{
	 				  var pageindex=parseInt($("[name='pageindexnew']").val());
	 				  if(pageindex==1){
	 					 $("#theone").nextAll().remove();
	 				  }
	 				  $("[name='pageindexnew']").val(pageindex-1);
	 			   }
	 		   }
	 	});
    }
    
    $("#sohot").click(function(){
    	$("[name='pageindexnew']").val(1);
    	newprosub();
    })
    $("#turnup").click(function(){
    	var pageindex=parseInt($("[name='pageindexnew']").val());
    	if(pageindex!=1){
    		$("[name='pageindexnew']").val(pageindex-1);	
    	}
    	newprosub();
    })
    $("#turnnext").click(function(){
    	var pageindex=parseInt($("[name='pageindexnew']").val());
    	$("[name='pageindexnew']").val(pageindex+1);
    	newprosub();  
    })
	
    $("#onlyproductname").click(function(){
    	//alert("aa");
    	 dialogNewub = art.dialog({
 	        title: "新增爆品",
 	        lock:true,
 	        content: document.getElementById('create')
 	    });
    	$("#productname").val("");
    	
    	$("[name='pageindexnew']").val(1);
     	newprosub();
    });
    $("#addprodiv").submit(function(){
    	var img= $("#addprodiv").find("[name='image']").val();
    	if(img==""){
    		alert("图片不能为空");
    		return false;
    	}
    	var proname=$("#onlyproductname").val();
    	if(proname==""){
    		alert("请选择产品");
    		return false;
    	}
    	
    });
    $("#updateprodiv").submit(function(){
    	var img= $("#updateprodiv").find("[name='image']").val();
    	if(img==""){
    		alert("图片不能为空");
    		return false;
    	}
    	
    });
    $("[name='isproOrpub']").click(function(){
    	$("[name='pageindexnew']").val(1);
    	$("#productname").val("");
    	newprosub();
    })
    
    /*------懒人版分割线------*/
    
    $("#addhotproslazy").click(function(){
    	$("#onlyhotformLazy").find(".showimg").attr("src","");
    	$("#onlyhotformLazy").find("[name='image']").val("");
    	$("#onlyhotformLazy").find("[name='productid']").val("");
    	$("#onlyhotformLazy").find("[name='url']").val("");
    	$("#onlyhotformLazy").find("[name='seq']").val("");
    	 dialog = art.dialog({
    	        title: "新增爆品",
    	        lock:true,
    	        content: document.getElementById('addprodivLazy')
    	    });
    });
    
    /*------懒人版分割线------*/
});

function sosuo(){
	var lpath =location.pathname;
	var pageNo = $("#pageNo").val();
	$("#soform").attr("action",lpath+"?pageNo="+pageNo);
 
	$("#soform").submit();
}


/*------懒人版分割线------*/


var exceldialoglazy=null;
function uploaddialog2(){
	exceldialoglazy = art.dialog.uploadFile("上传图片",{callback:"uploadcallbacklazy",userpath:"admin",extensions:"gif,jpg,png,jepg"});
}

function uploadcallbacklazy(response){
	exceldialoglazy.close();
	$("#onlyhotformLazy").find(".showimg").attr("src",response.url);
	$("#onlyhotformLazy").find("[name='image']").val(response.url)
	
}

/*------懒人版分割线------*/
</script>
</head>
<body>

	<div class="panel panel-info">
		<div class="panel-heading"> 
			  <form  id="soform" method="post"  > 
			  	 <!--   
				  <div class="input-group" style="width:200px;float: right;">
							<input type="text" class="form-control"  name="so_hotproductinfo"  value='${so_hotproductinfo!}' placeholder="排序号"> 
							<span class="input-group-btn">
								<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
							</span>
				  </div>
				   -->
			  </form>
			  <button type="button" id="addhotpros"  class="btn btn-info"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增爆品</button>
			  <button type="button" id="addhotproslazy"  class="btn btn-info"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增爆品（简易版）</button>
		</div>
		<table class="table table-hover table-bordered">

			<tr>
				<th width="5%">#</th>
				<th width="5%">产品id</th>
				<th width="15%">爆款图片</th>
				<th width="13%">爆款链接</th>
				<th width="5%">排序号</th>
				<th width="7%">点击次数</th>
				<th width="15%">创建时间</th>
				<th width="15%">修改时间</th>
				<th width="20%">操作</th>
			</tr>
 
			[#list pagination.list as hotpro]
			<tr>
				<td>${pagination.pageSize * (pagination.pageNo-1)+hotpro_index+1}</td>
				<td>${hotpro.productid!}</td>
				<td><img style="width: 50px;height: 50px;" src="${hotpro.image!}"> </td>
				<td>${hotpro.url!}</td>
				<td>${hotpro.seq!}</td>
				<td>${hotpro.clicks!}</td>
				<td>${(hotpro.createtime?string("yyyy-MM-dd"))!}</td>
				<td>${(hotpro.updatetime?string("yyyy-MM-dd"))!}</td>
				<td>
					<!--   
					<input value="修改" type="button" onclick="cha(${hotpro.id});" class="btn btn-danger btn-xs" />
					-->
					<input value="删除" type="button" onclick="del(${hotpro.id});" class="btn btn-danger btn-xs" />
					<input value="编辑" type="button" onclick="edit(${hotpro.id},'${hotpro.image!}','${hotpro.url!}',${hotpro.seq!});" class="btn btn-danger btn-xs" />
					[#if hotpro.isabled=1]
						<input value="禁用" type="button" onclick="enable(${hotpro.id},${hotpro.isabled!});" class="btn btn-danger btn-xs" />
					[/#if]
					[#if hotpro.isabled=0]
						<input value="启用" type="button" onclick="enable(${hotpro.id},${hotpro.isabled!});" class="btn btn-danger btn-xs" />
					[/#if]
				</td>
			</tr>
			[/#list]
		</table>
		
		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>

	<!--新增 -->

	<div id="create" style="display: none;width: 800px;height: 400px;" >
		<form  id="gethotproform"  role="form" method="post" class="form-inline">
			<input type="hidden" name="pageindexnew" value="1">
			<input type="hidden" name="pagesizenew" value="6">
			<div class="form-group">
				  <label>
				  		 <input type="text" class="form-control" id="productname" placeholder="请输入名称" name="productname">
				  </label>
			</div>
			<div class="form-group">
				  <label>
				  		 <button id="sohot" type="button" class="btn btn-default">搜索</button>
				  </label>
			</div>
			<div class="form-group">
				  <label>
				  		 <input type="radio"  name="isproOrpub" value="0" checked="checked">新品
				  		 <input type="radio"  name="isproOrpub" value="1" >产品 
				  </label>
			</div>
		</form>
		<div style="width: 100%;height: 80%;">
				<table class="table table-hover table-bordered" id="pubtable">
					 	<tr id="theone">
					 		<th width="10%">商品id</th>
					 		<th width="70%">商品名</th>
					 		<th width="20%">操作</th>
					 	</tr>
				</table>
		</div>
		<div style="width: 100%;height: 10%;margin-left: 80%">
			<input id="turnup" value="上一页" type="button"  class="btn btn-danger btn-xs" />
			<input id="turnnext" value="下一页" type="button"  class="btn btn-danger btn-xs" />
		</div>
		 
	</div>
	
	<div id="addprodiv" style="width: 900px;height: 500px;display: none;">
		 <form id="onlyhotform" action="insertHotpro.do" method="post" class="form-horizontal" role="form">
		 		<input type="hidden" name="hotproid">
		 		<div class="form-group">
				      <label  class="col-sm-2 control-label" id="clickforpro">选择产品</label>
				      <div class="col-sm-10">
				         <input style="cursor: pointer;" type="text" class="form-control"  
				            placeholder="点击选择" required="required" readonly="readonly"  id="onlyproductname">
				            <input type="hidden" name="productid"  id="onlyproductid">
				      </div>
			     </div>
		 		 <input type="hidden" id="onlyproducturl" name="url">
			     <div class="form-group">
				      <label  class="col-sm-2 control-label">排序号</label>
				      <div class="col-sm-10">
				         <input type="number" class="form-control" id="onlyseq" 
				            placeholder="请输入排序号" min="1" required="required" name="seq">
				      </div>
			     </div>
			     <div class="form-group">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button onclick="uploaddialog()" type="button" class="btn btn-default">添加爆款图片</button>
				         <input type="hidden" name="image" id="onlyimage">
				      </div>
   				</div>
   				<div style="width: 200px;height: 200px;margin-left: 160px;">
   					<img id="baoimg" style="width: 100%;height: 100%;" src="">
   				</div>
   				<div class="form-group" style="margin-top: 10px;">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button  type="submit"  class="btn btn-default">提交</button>
				      </div>
   				</div>
		 </form>
	</div>
	
	<div id="addprodivLazy" style="width: 900px;height: 500px;display: none;">
		 <form id="onlyhotformLazy" action="insertHotpro.do" method="post" class="form-horizontal" role="form">
		 		<div class="form-group">
				      <label  class="col-sm-2 control-label" id="clickforpro">产品id</label>
				      <div class="col-sm-10">
				         <input type="number" class="form-control" required="required" name="productid"><span>注：填写红色部分（http://azt365.com/product/<b style="color: red;">12345</b>.html）</span>
				      </div>
			    </div>
		 		<div class="form-group">
				      <label  class="col-sm-2 control-label" id="clickforpro">爆品路径</label>
				      <div class="col-sm-10">
				          <input type="text" class="form-control" required="required" name="url" placeholder="如：/product/xxxxx.html">
				      </div>
			     </div>
			     <div class="form-group">
				      <label  class="col-sm-2 control-label">排序号</label>
				      <div class="col-sm-10">
				         <input type="number" class="form-control" placeholder="请输入排序号" min="1" required="required" name="seq">
				      </div>
			     </div>
			     <div class="form-group">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button onclick="uploaddialog2()" type="button" class="btn btn-default">添加爆款图片</button>
				         <input type="hidden" name="image">
				      </div>
   				</div>
   				<div style="width: 200px;height: 200px;margin-left: 160px;">
   					<img class="showimg" style="width: 100%;height: 100%;" src="">
   				</div>
   				<div class="form-group" style="margin-top: 10px;">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button  type="submit"  class="btn btn-default">提交</button>
				      </div>
   				</div>
		 </form>
	</div>
	
	 <div id="updateprodiv" style="width: 900px;height: 500px;display: none;">
		 <form id="onlyhotform" action="insertHotpro.do" method="post" class="form-horizontal" role="form">
		 		 <input type="hidden" name="hotproid">
		 		 
			     <div class="form-group">
				      <label  class="col-sm-2 control-label">排序号</label>
				      <div class="col-sm-10">
				         <input type="number" class="form-control"  
				            placeholder="请输入排序号" min="1" required="required" name="seq">
				      </div>
			     </div>
			     <div class="form-group">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button onclick="uploaddialog()" type="button" class="btn btn-default">修改爆款图片</button>
				         <input type="hidden" name="image" id="onlyimage">
				      </div>
   				</div>
   				<div style="width: 200px;height: 200px;margin-left: 160px;">
   					<img id="baoimg" style="width: 100%;height: 100%;" src="">
   				</div>
   				<div class="form-group" style="margin-top: 10px;">
				      <div class="col-sm-offset-2 col-sm-10">
				         <button  type="submit"  class="btn btn-default">提交</button>
				      </div>
   				</div>
		 </form>
	</div>
</body>
</html>